#!/usr/bin/env bash

set -e

REPO_ROOT_DIR="$(git rev-parse --show-toplevel)"

files=$((git diff --cached --name-only --diff-filter=ACMR | grep -Ei "\.rs$") || true)
if [ ! -z "${files}" ]; then
    cargo +nightly fmt --all
    git add $(echo "$files" | paste -s -d " " -)
fi

